package plugin

import (
	"gitee.com/i2worker/colite"
)

// Referer 设置HTTP请求头中的Referer(只有调用Request.Visit才有效)
func Referer(c *colite.Collector) {
	c.OnResponse(func(r *colite.Response) {
		r.Ctx.Put("_referer", r.Request.URL.String())
	})

	c.OnRequest(func(r *colite.Request) {
		if ref := r.Ctx.Get("_referer"); ref != "" {
			r.Headers.Set("Referer", ref)
		}
	})
}
